#include "libcomm.h"

#define YEAR ((((__DATE__ [7] - '0') * 10 + (__DATE__ [8] - '0')) * 10 \
    + (__DATE__ [9] - '0')) * 10 + (__DATE__ [10] - '0'))
#define MONTH (__DATE__ [2] == 'n' ? (__DATE__ [1] == 'a' ? 0 : 5)  \
    : __DATE__ [2] == 'b' ? 1 \
    : __DATE__ [2] == 'r' ? (__DATE__ [0] == 'M' ? 2 : 3) \
    : __DATE__ [2] == 'y' ? 4 \
    : __DATE__ [2] == 'l' ? 6 \
    : __DATE__ [2] == 'g' ? 7 \
    : __DATE__ [2] == 'p' ? 8 \
    : __DATE__ [2] == 't' ? 9 \
    : __DATE__ [2] == 'v' ? 10 : 11)
#define DAY ((__DATE__ [4] == ' ' ? 0 : __DATE__ [4] - '0') * 10 \
    + (__DATE__ [5] - '0'))
#define DATE_AS_INT (((YEAR - 2000) * 12 + MONTH) * 31 + DAY)
 

const char* common_version()
{
	static String version(256);
	version.memset();
	version.sprintf("%s_(%d-%02d-%02d %s)", COMM_VERSION, YEAR, MONTH+1, DAY, __TIME__);

#if (COMM_FEATURE_STDLIST==1)
	version.strcat("_STDLIST");
#endif
#if (COMM_FEATURE_REGEX==1)
	version.strcat("_REGEX");
#endif
#if (COMM_FEATURE_CURL==1)
	version.strcat("_CURL");
#endif
#if (COMM_FEATURE_LIBEVENT==1)
	version.strcat("_LIBEVENT");
#endif
#if (COMM_FEATURE_SSL==1)
	version.strcat("_SSL");
#endif
	return version;
}


void common_dumpstack(int signo, FILE* stream)
{
	if(NULL != stream)
	{
		fprintf(stream,"%s",StackTracer::TraceStack().get());
	}
	else
	{
		common_log(MYLIB_LOG_ERR,"%s",StackTracer::TraceStack().get());
	}
}

// could not invoking any log function.
//
void common_log(int level, const char* format, ...)
{
	va_list args;
	va_start(args, format);
	Log::Instance()->VWrite(level,format,args);
	va_end(args);
	
}

